/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidade;

import controlo.util.Conexao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;


/**
 *
 * @author Lomanda
 */

public class MoedaDAO 
{
    Connection conn;
    List<SelectItem> listaMoedas;
    
    public MoedaDAO() 
    {
        
        try
        {
            conn = Conexao.getConnection();
        } catch (Exception ex) {
            Logger.getLogger(ContaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        listaMoedas = new LinkedList<SelectItem>();
    }
    
    public List<SelectItem> getTodasMoedas() throws Exception
    {
         //String h;
         try
         {
            conn = Conexao.getConnection();
            Statement stm = conn.createStatement();
            listaMoedas.add(new SelectItem( 0 ,"---"));
         //   listaMoedas.get(0).setDisabled(true);
         //   listaMoedas.get(0).setNoSelectionOption(true);
           
            
            ResultSet res = stm.executeQuery("SELECT * FROM moeda order by idMoeda");
            
            while(res.next())
            {
                listaMoedas.add(new SelectItem(res.getInt("idMoeda"),res.getString("nomeMoeda")));
            }
            
            res.close();
            stm.close();
         }
         catch(Exception e)
         {
             e.printStackTrace();
         }

         return listaMoedas;
    }
}
